package com.example.shuiyin.exception;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ErrorCode {

    // 系统错误：1000-1999
    INTERNAL_SERVER_ERROR(1000, "系统内部错误", HttpStatus.INTERNAL_SERVER_ERROR),
    INTERNAL_ERROR(1001, "内部服务错误", HttpStatus.INTERNAL_SERVER_ERROR),
    SERVICE_UNAVAILABLE(1002, "服务暂时不可用", HttpStatus.SERVICE_UNAVAILABLE),
    
    // 认证与授权错误：2000-2999
    INVALID_CREDENTIALS(2000, "用户名或密码错误", HttpStatus.UNAUTHORIZED),
    TOKEN_EXPIRED(2001, "Token已过期", HttpStatus.UNAUTHORIZED),
    TOKEN_INVALID(2002, "无效的Token", HttpStatus.UNAUTHORIZED),
    FORBIDDEN(2003, "没有权限执行此操作", HttpStatus.FORBIDDEN),
    UNAUTHORIZED(2004, "未授权访问", HttpStatus.UNAUTHORIZED),
    TOO_MANY_REQUESTS(2005, "请求频率过高", HttpStatus.TOO_MANY_REQUESTS),
    
    // 用户错误：3000-3999
    USER_NOT_FOUND(3000, "用户不存在", HttpStatus.NOT_FOUND),
    USER_ALREADY_EXISTS(3001, "用户已存在", HttpStatus.CONFLICT),
    USERNAME_ALREADY_EXISTS(3002, "用户名已存在", HttpStatus.CONFLICT),
    EMAIL_ALREADY_EXISTS(3003, "邮箱已被使用", HttpStatus.CONFLICT),
    PHONE_ALREADY_EXISTS(3004, "手机号已被使用", HttpStatus.CONFLICT),
    INVALID_PASSWORD(3005, "密码错误", HttpStatus.BAD_REQUEST),
    
    // 文件错误：4000-4999
    FILE_NOT_FOUND(4000, "文件不存在", HttpStatus.NOT_FOUND),
    FILE_UPLOAD_ERROR(4001, "文件上传失败", HttpStatus.INTERNAL_SERVER_ERROR),
    FILE_DELETE_ERROR(4002, "文件删除失败", HttpStatus.INTERNAL_SERVER_ERROR),
    FILE_TOO_LARGE(4003, "文件大小超过限制", HttpStatus.BAD_REQUEST),
    INVALID_FILE_TYPE(4004, "不支持的文件类型", HttpStatus.BAD_REQUEST),
    FILE_SIZE_EXCEEDED(4005, "文件大小超过限制", HttpStatus.BAD_REQUEST),
    UNSUPPORTED_FILE_TYPE(4010, "不支持的文件类型", HttpStatus.BAD_REQUEST),
    
    // 资源错误：5000-5999
    RESOURCE_NOT_FOUND(5000, "资源不存在", HttpStatus.NOT_FOUND),
    RESOURCE_ALREADY_EXISTS(5001, "资源已存在", HttpStatus.CONFLICT),
    SYSTEM_BUSY(5002, "系统繁忙", HttpStatus.SERVICE_UNAVAILABLE),
    INVALID_STATE(5003, "无效的状态", HttpStatus.BAD_REQUEST),
    
    // 参数错误：6000-6999
    INVALID_PARAMETER(6000, "无效的参数", HttpStatus.BAD_REQUEST),
    MISSING_PARAMETER(6001, "缺少必要参数", HttpStatus.BAD_REQUEST),
    BAD_REQUEST(6002, "错误的请求", HttpStatus.BAD_REQUEST),
    
    // 业务逻辑错误：7000-7999
    STORAGE_QUOTA_EXCEEDED(7000, "存储空间不足", HttpStatus.FORBIDDEN),
    QUOTA_EXCEEDED(7001, "处理配额不足", HttpStatus.FORBIDDEN),
    OPERATION_NOT_ALLOWED(7002, "操作不允许", HttpStatus.BAD_REQUEST),
    WATERMARK_PROCESS_ERROR(7003, "水印处理失败", HttpStatus.INTERNAL_SERVER_ERROR);

    private final int code;
    private final String message;
    private final HttpStatus httpStatus;
    
    public int getCode() {
        return code;
    }
    
    public String getMessage() {
        return message;
    }
    
    public HttpStatus getHttpStatus() {
        return httpStatus;
    }

    public String formatMessage(Object... args) {
        if (args == null || args.length == 0) {
            return message;
        }
        return String.format(message, args);
    }
} 